<template>
	<view>
		<view class="content">
			<view class="list">

				<view class="row" v-if="is_shop" @click="topage('/pages/supplier/index')">
					<view class="title">绑定供应商</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="row" @click="topage('change_name')">
					<view class="title">修改昵称</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<!-- #ifndef MP-WEIXIN -->
				<view class="row" @click="topage('../password/index')">
					<view class="title">修改密码</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<!-- #endif -->
				<view class="row" @click="topage('../paypassword/index')">
					<view class="title">支付密码</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="row">
					<view class="title">当前版本</view>
					<view class="right">
						<view class="tis">{{version}}</view>
						<view class="icon xiangyou"></view>
					</view>
				</view>

				<view class="row" @click="clearcache()">
					<view class="title">清理缓存</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<!-- #endif -->


			</view>
			<view class="btn" @click="login_out">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import {
		UserIndex,
		UserInfo,
		forUpload_1
	} from "@/api/api.js"
	export default {
		data() {
			return {
				user: [],
				name: '',
				isShow: false,
				version: '',
				cacheSize: '',
				is_shop: false
			};
		},
		onLoad() {
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, (inf) => {
				this.version = inf.version; //获取当前版本号
			});
			let self = this;
			plus.cache.calculate(size => {
				if (size < 1024) {
					self.cacheSize = size + 'B';
				} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
					self.cacheSize = Math.floor((size / 1024) * 100) / 100 + 'KB';
				} else if (size / 1024 / 1024 >= 1) {
					self.cacheSize = Math.floor((size / 1024 / 1024) * 100) / 100 + 'M';
				}
			});
			// #endif
			this.UserIndex()
		},
		methods: {
			clearcache() {
				// #ifdef APP-PLUS
				let self = this;
				plus.cache.clear(res => {
					uni.showToast({
						title: '清除成功！',
						icon: 'none',
						success() {
							self.cacheSize = '0B';
						}
					});
				});
				// #endif
			},
			login_out() {
				uni.setStorageSync('token', '')
				uni.switchTab({
					url: '/pages/tabBar/user/user'
				})
			},
			topage(url) {
				uni.navigateTo({
					url
				})
			},
			changeImg() {
				let that = this
				uni.chooseImage({
					count: 1,
					success: function(res) {

						uni.getImageInfo({
							src: res.tempFilePaths[0],
							success: (res1) => {
								console.log(res1);

								uni.uploadFile({
									url: getApp().globalData.data.requestUrl +
										'/User/forUpload_1',
									methods: 'post',
									header: {
										'token': uni.getStorageSync('token'),
										'Content-Type': 'multipart/form-data'
									},
									name: 'image',
									fileType: 'image',
									filePath: res1.path,
									success: (res2) => {
										console.log(JSON.parse(res2.data));
										let res3 = JSON.parse(res2.data)
										that.user.head_url = res3.data.path
									}
								})
							}
						});
					}
				});
			},
			changeName(name) {
				if (this.name == name) {
					this.isShow = false
					return uni.$showMsg('无变化')
				}
				UserInfo({
					name: this.name
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.isShow = false
					this.UserIndex()
				})
			},
			showInput() {
				this.isShow = true
			},
			UserIndex() {
				UserIndex().then(res => {
					this.user = res.data.info
					this.name = this.user.username
					if (this.user.is_shop == 1) {
						this.is_shop = true
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.4);
		width: 70%;
		height: 40px;
		border-radius: 40px;
		background-color: #f06c7a;
		color: #fff;
		justify-content: center;
		align-items: center;
		font-size: 15px;
		display: flex;
		margin: 30px auto;
	}

	page {
		background-color: #f3f3f3;
	}

	.icon {
		font-size: 30upx;

	}

	.content {
		padding-bottom: 20upx;

		.list {
			width: 96%;
			padding-left: 4%;
			background-color: #fff;
			margin-bottom: 20upx;

			.row {
				widows: 100%;
				min-height: 90upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: solid 1upx #eee;

				&:last-child {
					border-bottom: none;
				}

				.title {
					font-size: 32upx;
					color: #333;
				}

				.right {
					display: flex;
					align-items: center;
					color: #999;

					.tis {
						font-size: 26upx;
						margin-right: 5upx;
						max-height: 120upx;

						image {
							width: 100upx;
							height: 100upx;
							border-radius: 100%;
							margin: 10upx 0;
						}
					}

					.icon {
						width: 40upx;
						color: #cecece;
					}
				}

			}
		}
	}
</style>